import i18n from '@root/i18n';
import { savePlayer, updateRankData } from '../../../../data';

export const tower: GameEntity = world.querySelector('#冰系魔法塔')!;
tower.interactColor = new GameRGBColor(1, 1, 1);
tower.interactHint = '冰系魔法塔 / Ice Tower';
tower.interactRadius = 5;
tower.onInteract(async ({ entity }) => {
  const result = await entity.player.dialog({
    type: GameDialogType.SELECT,
    title: i18n.t('tower_title', { lng: entity.player.lng }),
    content: i18n.t('tower_content', { lng: entity.player.lng }),
    options: [
      i18n.t('yes', { lng: entity.player.lng }),
      i18n.t('no', { lng: entity.player.lng }),
    ],
  });
  if (!result || result?.value === i18n.t('no', { lng: entity.player.lng })) {
    return;
  }
  entity.position.copy(new GameVector3(88, 104, 213));
  if (entity.player.canFly) {
    return;
  }
  entity.player.canFly = true;
  const time = (Date.now() - entity.startTime) / 1000;
  entity.player.directMessage(i18n.t('end_', { lng: entity.player.lng, time }));
  if (time < entity.data.time || entity.data.time === 0) {
    entity.data.time = time;
    savePlayer(entity as GamePlayerEntity);
    updateRankData(entity as GamePlayerEntity);
  }
});
tower.enableInteract = true;
